package com.ssm.service.impl;

import com.github.abel533.entity.Example;
import com.ssm.mapper.UserMapper;
import com.ssm.pojo.SysLog;
import com.ssm.pojo.User;
import com.ssm.service.UserService;
import com.ssm.service.commonService.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 * @author minghaozhi
 * @date 2017/12/23
 */
@Service("userService")
public class UserServiceImpl extends CommonService<User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByLoginName(String loginName) {
        User param = new User();
        param.setLoginName(loginName);
        param.setStatus(1);
        User user = this.userMapper.selectOne(param);
        if (user != null) {
            return user;
        } else {
            return null;
        }
    }
    @Override
    public List<String> queryAllPerms(Long userId) {
        return userMapper.queryAllPerms(userId);
    }

    @Override
    public List<Long> queryAllMenuId(Long userId) {
        return userMapper.queryAllMenuId(userId);
    }

    /**
     * 修改用户密码
     * @param userId
     * @param password
     * @param newPassword
     * @return
     */
    @Override
    public Integer updatePassword(Long userId, String password, String newPassword, SysLog sysLog) {
        Integer count=0;
        User param=new User();
        param.setUserId(userId);
        param.setPassword(password);
        User user=this.userMapper.selectOne(param);
        if (user!=null){
            user.setPassword(newPassword);
            user.setUpdateBy(user.getUserId());
            user.setUserName(user.getUserName());
            user.setUpdateTime(new Date());
            count+=this.userMapper.updateByPrimaryKeySelective(user);

        }
        return count;
    }
}
